package it.poste.il.compensatore.entities;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@Table(name="operations")
public class Operation extends BaseEntity {

	private static final long serialVersionUID = 3073608928802999460L;

	private int operation;
	private String operationName;
	private String urlEndpoint;
	private String operationType;
	private int avoidMode;
	private String avoidOperation;
	private String urlAvoidEndpoint;
	private String objHelper;

	@OneToMany(fetch=FetchType.LAZY, cascade=CascadeType.ALL, mappedBy="operationId", targetEntity=Message.class)
	private List<Message> message;
	
	public List<Message> getMessage() {
		return message;
	}

	public void setMessage(List<Message> message) {
		this.message = message;
	}

	public int getOperation() {
		return operation;
	}

	public void setOperation(int operation) {
		this.operation = operation;
	}

	public String getOperationName() {
		return operationName;
	}
	
	public void setOperationName(String operationName) {
		this.operationName = operationName;
	}
	
	public String getUrlEndpoint() {
		return urlEndpoint;
	}
	
	public void setUrlEndpoint(String urlEndpoint) {
		this.urlEndpoint = urlEndpoint;
	}
	
	public String getOperationType() {
		return operationType;
	}
	
	public void setOperationType(String operationType) {
		this.operationType = operationType;
	}
	
	public int getAvoidMode() {
		return avoidMode;
	}
	
	public void setAvoidMode(int avoidMode) {
		this.avoidMode = avoidMode;
	}
	
	public String getAvoidOperation() {
		return avoidOperation;
	}
	
	public void setAvoidOperation(String avoidOperation) {
		this.avoidOperation = avoidOperation;
	}
	
	public String getUrlAvoidEndpoint() {
		return urlAvoidEndpoint;
	}
	
	public void setUrlAvoidEndpoint(String urlAvoidEndpoint) {
		this.urlAvoidEndpoint = urlAvoidEndpoint;
	}
	
	public String getObjHelper() {
		return objHelper;
	}
	
	public void setObjHelper(String objHelper) {
		this.objHelper = objHelper;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + avoidMode;
		result = prime * result
				+ ((avoidOperation == null) ? 0 : avoidOperation.hashCode());
		result = prime * result + ((message == null) ? 0 : message.hashCode());
		result = prime * result
				+ ((objHelper == null) ? 0 : objHelper.hashCode());
		result = prime * result + operation;
		result = prime * result
				+ ((operationName == null) ? 0 : operationName.hashCode());
		result = prime * result
				+ ((operationType == null) ? 0 : operationType.hashCode());
		result = prime
				* result
				+ ((urlAvoidEndpoint == null) ? 0 : urlAvoidEndpoint.hashCode());
		result = prime * result
				+ ((urlEndpoint == null) ? 0 : urlEndpoint.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Operation other = (Operation) obj;
		if (avoidMode != other.avoidMode)
			return false;
		if (avoidOperation == null) {
			if (other.avoidOperation != null)
				return false;
		} else if (!avoidOperation.equals(other.avoidOperation))
			return false;
		if (message == null) {
			if (other.message != null)
				return false;
		} else if (!message.equals(other.message))
			return false;
		if (objHelper == null) {
			if (other.objHelper != null)
				return false;
		} else if (!objHelper.equals(other.objHelper))
			return false;
		if (operation != other.operation)
			return false;
		if (operationName == null) {
			if (other.operationName != null)
				return false;
		} else if (!operationName.equals(other.operationName))
			return false;
		if (operationType == null) {
			if (other.operationType != null)
				return false;
		} else if (!operationType.equals(other.operationType))
			return false;
		if (urlAvoidEndpoint == null) {
			if (other.urlAvoidEndpoint != null)
				return false;
		} else if (!urlAvoidEndpoint.equals(other.urlAvoidEndpoint))
			return false;
		if (urlEndpoint == null) {
			if (other.urlEndpoint != null)
				return false;
		} else if (!urlEndpoint.equals(other.urlEndpoint))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return this.getClass().getName() + " [id=" + getId() + ", operation=" + operation + ", operationName="
				+ operationName + ", urlEndpoint=" + urlEndpoint
				+ ", operationType=" + operationType + ", avoidMode="
				+ avoidMode + ", avoidOperation=" + avoidOperation
				+ ", urlAvoidEndpoint=" + urlAvoidEndpoint + ", objHelper="
				+ objHelper + "]";
	}
	
}
